define([
  'jquery',
  'underscore',
  'backbone',
  'd3',
  'collections/studies',
  'collections/sample_sets',
  'collections/transcripts',
  'views/select_study',
  'views/select_sample_sets',
  'views/select_transcripts'
], function($, _, Backbone, d3, 
  StudyCollection, 
  SampleSetCollection,
  TranscriptCollection,
  SelectStudyView,
  SelectSampleSetsView,
  SelectTranscriptsView) {

  // models/collections
  var studies = new StudyCollection;
  var selectedSampleSets = new SampleSetCollection;
  var selectedTranscripts = new TranscriptCollection;

  // views
  // choose a study
  selectStudyView = new SelectStudyView({ 
    el: '#select-study',
    collection: studies
  });
  // choose sample sets
  var selectSampleSetsView = new SelectSampleSetsView({
    el: '#select-sample-sets',
    parentView: selectStudyView,
    selectedItems: selectedSampleSets
  });
  // search for transcripts
  var selectTranscriptsView = new SelectTranscriptsView({
    el: '#select-transcripts',
    parentView: selectStudyView,
    selectedItems: selectedTranscripts
  });

  // render
  selectStudyView.render();

  // button click functions
  function toggle_visibility(id) {
    var e = document.getElementById(id);
    if(e.style.display == 'block')
      e.style.display = 'none';
    else
      e.style.display = 'block';
  }
  function toggle_off(id) {
    var e = document.getElementById(id);
    e.style.display = 'none';
  }
  function toggle_on(id) {
    var e = document.getElementById(id);
    e.style.display = 'block';
  }
  // button events
  $('#Choose_Study_Btn').click(function() {
    toggle_off('Home');
    toggle_off('div-select-sample-sets');
    toggle_off('div-select-transcripts');
    toggle_off('Heatmap');
    toggle_off('Selections');
    toggle_on('Choose_Study')
  });
  $('#Sample_Set_Btn').click(function() {
    toggle_off('Home');
    toggle_off('Choose_Study');
    toggle_on('div-select-sample-sets');    
  });
  $('#Transcript_Btn').click(function() {
    toggle_off('Home');
    toggle_off('Choose_Study');
    toggle_on('div-select-transcripts');
  });
  $('#Heatmap_Btn').click(function() {
    toggle_off('Home');
    toggle_off('Choose_Study');
    toggle_on('Heatmap');
  });
  $('#Selections_Btn').click(function() {
    toggle_off('Home');
    toggle_off('Choose_Study');
    toggle_on('Selections');
  });
  $('#btn-get-started').click(function() {
    toggle_off('Home');
    toggle_on('Choose_Study');
  });
  $('#btn-select-sample-sets').click(function() {
    toggle_off('Choose_Study');
    toggle_on('div-select-sample-sets');
  });
  $('#btn-select-transcripts').click(function() {
    toggle_off('Choose_Study');
    toggle_on('div-select-transcripts');
  });
  $('#btn-close-sample-set').click(function() { toggle_off('div-select-sample-sets'); });
  $('#btn-close-transcript').click(function() { toggle_off('div-select-transcripts'); });
  $('#btn-close-heatmap').click(function() { toggle_off('Heatmap'); });
  $('#btn-close-selections').click(function() { toggle_off('Selections'); });

});
